package com.neymar.controller;


import com.neymar.entity.Progress;
import com.neymar.logEnum.ObjectionTypeEnum;
import com.neymar.service.LogService;
import com.neymar.service.ProgressService;
import com.neymar.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 求职进度表 前端控制器
 * </p>
 *
 * @author neymar
 * @since 2021-06-02
 */
@RestController
@RequestMapping("/progress")
@Api(tags = {"用户求职进度信息操作接口"})
public class ProgressController {

    @Autowired
    private ProgressService progressService;

    @Autowired
    private LogService logService;

    @ApiOperation("保存求职者的求职进度")
    @PostMapping("/save/{operatorId}")
    public R save(@RequestBody Progress progress,
                  @PathVariable("operatorId") String operatorId) {
        int flag = progressService.save(progress);
        if (flag != 0) {
            logService.save(operatorId, 1, 3);
            return R.ok();
        }
        return R.fail();
    }

    @ApiOperation("根据ID查看求职者进度")
    @GetMapping("/find/{userId}/{operatorId}")
    public R findUser(@PathVariable("userId") String userId,
                      @PathVariable("operatorId") String operatorId) {
        logService.save(operatorId, 1, 3);

        return R.ok(progressService.findProgress(userId));
    }

    @ApiOperation("根据ID删除求职者进度")
    @DeleteMapping("/delete/{userId}")
    public R deleteProgressById(@PathVariable("userId") String userId) {
        int flag = progressService.deleteProgressById(userId);
        if (flag != 0) {
            logService.save(userId, 1, 3);
            return R.ok();
        }
        return R.fail();

    }

    @ApiOperation("根据ID更新求职者进度")
    @PutMapping("/update/{userId}/{operatorId}")
    public R updateProgressById(@RequestBody Progress progress,
                                @PathVariable("operatorId") String operatorId) {
        int flag = progressService.updateProgressById(progress);
        if (flag != 0) {
            logService.save(operatorId, 1, 3);
            return R.ok();
        }
        return R.fail();
    }

}

